package com.company.ex03.pyrmont.connector.http;

import util.StringManager;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author zhangyongshuai
 * @Date 2022/1/4
 */
public final class ParameterMap extends HashMap {
    public ParameterMap(){
        super();
    }

    public ParameterMap(int initialCapacity) {
        super(initialCapacity);
    }

    public ParameterMap(int initialCapacity, float loadFactor) {
        super(initialCapacity, loadFactor);
    }

    public ParameterMap(Map map) {
        super(map);
    }

    private boolean locked = false;
    public boolean isLocked() {
        return (this.locked);
    }

    public void setLocked(boolean locked) {
        this.locked = locked;
    }

    private static final StringManager sm = StringManager.getManager("util");

    @Override
    public void clear() {
        if (locked) {
            throw new IllegalStateException(sm.getString("parameterMap.locked"));
        }
        super.clear();
    }

    @Override
    public Object put(Object key, Object value) {
        if (locked) {
            throw new IllegalStateException(sm.getString("parameterMap.locked"));
        }
        return (super.put(key, value));
    }

    @Override
    public void putAll(Map map) {
        if (locked) {
            throw new IllegalStateException(sm.getString("parameterMap.locked"));
        }
        super.putAll(map);
    }

    @Override
    public Object remove(Object key) {
        if (locked) {
            throw new IllegalStateException(sm.getString("parameterMap.locked"));
        }
        return (super.remove(key));
    }
}
